import {fetch, ProxyAgent} from 'undici'

// 创建代理实例
const proxyUrl = 'http://127.0.0.1:10809';
const agent = new ProxyAgent(proxyUrl)

async function testFetch() {
    try {
        const res = await fetch("http://www.ggdwx.net/search?keyword=重生&page=1", {
            method: 'POST',
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 OPR/77.0.4054.203",
            },
            dispatcher: agent
        });

        console.log("res status:", res.status);
        const resText = await res.text();
        console.log("res text:", resText);
        console.log("res header:", res.headers);
    } catch (error) {
        console.error('Fetch error:', error);
    }
}

await testFetch();
